package com.educate.member.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.device.model.bo.FamilyBO;
import com.educate.member.rpc.api.FamilyService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("family")
public class FamilyController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private FamilyService familyService;

    @PostMapping(value = "/create")
    public R create(@RequestBody FamilyBO bo) {
        familyService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody FamilyBO bo) {
        familyService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{familyId}")
    public R delete(@PathVariable String familyId) {
        familyService.delete(familyId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{familyId}")
    public R<FamilyBO> detail(@PathVariable String familyId) {
        FamilyBO bo = familyService.detail(familyId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<FamilyBO> detail(@RequestBody FamilyBO bo) {
        FamilyBO detail = familyService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<FamilyBO> update(@RequestBody FamilyBO bo) {
        familyService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<FamilyBO>> query(@RequestBody FamilyBO bo) {
        Page<FamilyBO> result = familyService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<FamilyBO>> list(@RequestBody FamilyBO bo) {
        List<FamilyBO> result = familyService.list(bo);
        return R.ok(result);
    }

}
